package com.briup.cms.web.controller;

import com.briup.cms.util.Result;
import com.briup.cms.util.ResultCode;
import com.briup.cms.util.UploadUtils;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api("文件上传模块")
@RestController
@RequestMapping("/auth")
@Slf4j
public class FileUploadController {
    @Autowired
    private UploadUtils uploadUtils;
    @PostMapping("/upload")
    public Result upload(MultipartFile img){
        try {
            String url= uploadUtils.fileToOSS(img);
            return Result.success(url);
        } catch (Exception e) {
            log.error("图片文件上传失败");
            return Result.failure(ResultCode.FILEUPLOAD_FAIL);
        }

    }
}
